<template>
	<view class="statistics">
		<!-- <g-navbar :isShowBack="false" backgroundColor="#365fff"></g-navbar> -->
		<view class="top-bar">
			<view class="welcome-slogan">
				{{userInfo?`欢迎您,${userInfo.nickname}`:'未登录'}}
			</view>
			<i class="iconfont icon-notice icon" @click="jump('/pages_notice/notice/notice')" />
		</view>
		<view class="notice-bar" v-if="notice"
			@click="jump(`/pages_notice/notice_detail/noticeDetail?id=${notice.id}`)">
			<view class="label">
				{{notice.created_at}}公告：
			</view>
			<view class="notice-main">
				<uni-notice-bar scrollable single :text="notice.content" style="width: 100%;" />
			</view>
		</view>
		<view class="main">
			<transactionStatistice />
			<levelProcess :processCount="processCount" />
			<headCount />
			<!-- <g-button icon="add" btn_text="新增后台（助手）" :width="686" :height="100" :borderRadius="24"></g-button> -->
			<view class="lucky-draw-wrapper">
				<view class="play-btn" @click="jump('/pages/home/home')">

				</view>
			</view>
		</view>
		<g-tabbar v-show="version === VERSION_TYPE.OFFICAL_VERSION" />
	</view>
</template>

<script lang="ts" setup>
	import transactionStatistice from './components/transactionStatistice/transactionStatistice.vue';
	import levelProcess from './components/levelProcess/levelProcess.vue';
	import headCount from './components/headCount/headCount.vue';
	import { onLoad, onHide, onShow } from '@dcloudio/uni-app';
	import interceptor from '@/router/router.interceptor';
	import { Ref, ref } from 'vue';
	import { VERSION_TYPE } from '@/enum/version';
	import dayjs from 'dayjs';
	import REST_URL from '@/http/http.restUrl';
	import { useStore } from 'vuex';
	import { removeHTMLTag, escape2Html } from '@/utils';
	import { INotice } from '@/types/notice';
	import { GET_STORE_USERINFO } from '@/store/gettersType';

	const store = useStore();


	const notice : Ref<INotice | null> = ref(null);
	

	const processCount : Ref<number> = ref(0);
	
	
	
	const testUserInfo = store.getters[GET_STORE_USERINFO].id;


	onHide(() => {
		processCount.value = 0;
	})

	onShow(() => {
		processCount.value = 66;
	})

	onLoad(async () => {
		interceptor.beforeEach({ url: '/pages/statistics/statistics' });
		getNewSystemNotice();
	})


	const getNewSystemNotice = async () : Promise<void> => {
		const result : INotice | null = (await uni.http.POST(REST_URL.singleSystemNotice, {
			// customer_id: store.state.userInfo.id,
		})).data
		if (result && result.content) {
			const str : string = escape2Html(removeHTMLTag(result.content)).trim();
			console.log(notice.value)
			const temp : string[] = [];
			for (let item of str) {
				if (item.trim()) {
					temp.push(item);
				}
			}
			notice.value = result;
			notice.value.content = temp.join('');
			notice.value.created_at = dayjs(result.created_at).format('MM-DD');
		}
	}






	const jump = (path : string) => {
		uni.router.route(path)
	}
</script>

<style scoped lang="scss">
	@import "./statistics.scss";
</style>